<template>
	<div class="floatbutstyle">
		<h2 class="mt15 mb15">{{ datas.text }}</h2>
		<el-tabs type="border-card" :stretch="true">
			<el-tab-pane label="内容">
				<div class="decorate-card">
					<div class="title">图标展示</div>

					<el-form ref="form" :model="datas" label-width="100px">
						<el-form-item label="状态">
							<el-radio-group v-model="datas.show">
								<el-radio :label="0">关闭</el-radio>
								<el-radio :label="1">开启</el-radio>
							</el-radio-group>
						</el-form-item>

						<el-form-item label="悬浮样式">
							<el-radio-group v-model="datas.mode">
								<el-radio :label="0">水平</el-radio>
								<el-radio :label="1">垂直</el-radio>
							</el-radio-group>
						</el-form-item>

						<el-form-item label="显示名称">
							<el-radio-group v-model="datas.isText">
								<el-radio :label="0">不显示</el-radio>
								<el-radio :label="1">显示</el-radio>
							</el-radio-group>
						</el-form-item>

						<el-form-item label="按钮位置">
							<el-radio-group v-model="datas.butPosition">
								<el-radio :label="0">左下角</el-radio>
								<el-radio :label="1">右下角</el-radio>
								<el-radio :label="2">左上角</el-radio>
								<el-radio :label="3">右上角</el-radio>
							</el-radio-group>
						</el-form-item>

						<el-form-item label="按钮文字颜色">
							<el-input v-model="datas.color">
								<template #append>
									<el-color-picker v-model="datas.color" />
								</template>
							</el-input>
						</el-form-item>

						<el-form-item label="背景颜色">
							<el-input v-model="datas.backgroundColor">
								<template #append>
									<el-color-picker v-model="datas.backgroundColor" />
								</template>
							</el-input>
						</el-form-item>

						<el-form-item label="按钮背景颜色">
							<el-input v-model="datas.buttonColor">
								<template #append>
									<el-color-picker v-model="datas.buttonColor" />
								</template>
							</el-input>
						</el-form-item>

						<el-form-item label="按钮图标颜色">
							<el-input v-model="datas.iconColor">
								<template #append>
									<el-color-picker v-model="datas.iconColor" />
								</template>
							</el-input>
						</el-form-item>

						<div class="title">功能图标</div>

						<vuedraggable :list="datas.list" item-key="index" :forceFallback="true" :animation="200">
							<template #item="{ element, index }">
								<section class="imgBanner">
									<el-form-item label="按钮图片">
										<div class="sd-flex">
											<div class="choice-image choice-image-delete" @click="openFileChoiceDialog(index)">
												<el-image v-if="element.src != ''" :src="STATIC_URL + element.src" fit="cover" class="cover-image" />
												<el-icon v-else>
													<ele-Plus />
												</el-icon>

												<div class="delete-content" @click.stop="element.src = ''" v-if="element.src != ''">
													<SvgIcon name="ele-DeleteFilled"></SvgIcon>
												</div>
											</div>
											<div class="ml10 tip">建议尺寸: 80*80</div>
										</div>
									</el-form-item>
									<el-form-item label="按钮名称">
										<el-input v-model="element.title.text">
											<template #append>
												<el-color-picker v-model="element.title.color" />
											</template>
										</el-input>
									</el-form-item>
									<el-form-item label="按钮链接">
										<el-input v-model="element.url">
											<template #append> <el-button class="ml5 mr5" @click="openChoiceData(index)">选择</el-button> </template>
										</el-input>
									</el-form-item>
									<van-icon class="el-icon-circle-close" name="close" @click="deleteInfo(index)" />
								</section>
							</template>
						</vuedraggable>
						<el-button @click="add"> 添加 </el-button>
					</el-form>
				</div>
			</el-tab-pane>
			<!-- <el-tab-pane label="样式">
				<DataStyle :datas="datas.dataStyle"></DataStyle>
			</el-tab-pane> -->
			<el-tab-pane label="数据">
				<StyleComponentData :datas="datas"></StyleComponentData>
			</el-tab-pane>
		</el-tabs>

		<FileChoice ref="FileChoiceRef" @choiceFile="choiceFile"></FileChoice>
		<PageData ref="PageDataRef" @choice="choicePage"></PageData>
	</div>
</template>

<script setup lang="ts" name="floatbutstyle">
import vuedraggable from 'vuedraggable'; //拖拽组件
import { reactive, ref, defineAsyncComponent } from 'vue';

import { STATIC_URL } from '/@/utils/config';
const FileChoice = defineAsyncComponent(() => import('/@/views/file/choice/index.vue'));
const FileChoiceRef = ref();
const PageData = defineAsyncComponent(() => import('/@/views/shop/data/page/choice/index.vue'));
const PageDataRef = ref();

let props = defineProps({
	datas: {},
});

/* 删除图片 */
let deleteInfo = (index: number) => {
	props.datas.list.splice(index, 1);
};

let choiceImageIndex = 0;
const openFileChoiceDialog = (index) => {
	choiceImageIndex = index;
	FileChoiceRef.value.openFileChoiceDialog();
};

const choiceFile = (res) => {
	props.datas.list[choiceImageIndex].src = res[0].visitRelativePath;
};

let choicePageIndex = 0;
const openChoiceData = (index) => {
	PageDataRef.value.openDialog();
	choicePageIndex = index;
};

const choicePage = (res) => {
	props.datas.list[choicePageIndex].url = res.urlContent;
};

let add = () => {
	props.datas.list.push({
		src: '',
		title: {
			text: '',
			color: '',
		},
		url: '',
	});
};
</script>

<style scoped lang="scss">
.floatbutstyle {
	.imgBanner {
		padding: 6px 12px;
		margin: 16px 7px;
		border-radius: 2px;
		background-color: #fff;
		box-shadow: 0 0 4px 0 rgba(10, 42, 97, 0.2);
		position: relative;

		&:hover {
			.el-icon-circle-close {
				display: block;
			}
		}
		/* 删除图标 */
		.el-icon-circle-close {
			position: absolute;
			right: -5px;
			top: -10px;
			cursor: pointer;
			font-size: 19px;
			display: none;
		}
	}
}

.el-tabs--border-card {
	:deep(.el-tabs__content) {
		padding: 0px !important;
	}
	border: 0px;

	:deep(.el-tabs__header) {
		background-color: #d9d9d9 !important;
	}
}

:deep(.el-input-group__prepend) {
	padding: 0px !important;
}

:deep(.el-input-group__append) {
	padding: 0px !important;
}

:deep(.el-color-picker__trigger) {
	padding: 0px;
}

:deep(.el-color-picker__color) {
	border: 0px;
}
</style>
